const { program } = require('commander')

const myParseInt = function(value) {
  console.log(value);
  return value;
}

program
  .command('add')
  .argument('<first>', 'integer argument', myParseInt)
  .argument('[second]', 'integer argument', myParseInt, 1000)
  .parse(process.argv)
  .action((first, second) => {
    console.log(`${first} + ${second} = ${first + second}`);
  })
;

// 选项则使用.opts()来获取选项值   process.argv 属性返回一个数组，这个数组包含了启动Node.js进程时的命令行参数
const options = program.opts();
console.log(options);